<template>
  <div style="width:500px;height:670px;margin:50px auto 0 auto;background:#efefef;padding:30px 0 0 50px; border-radius:45px">
    <span>修改个人信息</span>
      <el-form ref="form" :model="form" label-width="100px" >
        <el-form-item label="姓名:">
          <el-input v-model="form.name" ></el-input>
        </el-form-item>
        <el-form-item v-if="isLimit" label="身份:">
          <el-select v-model="form.type" >
             <el-option
                label="管理员"
                value="0">
            </el-option>
            <el-option
              label="业主"
              value="1">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="性别:">
          <el-select v-model="form.gender" placeholder="请选择性别" >
                <el-option
                label="男"
                value="0">
                </el-option>
                <el-option
                label="女"
                value="1">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="手机号:">
          <el-input v-model="form.phone" ></el-input>
        </el-form-item>
        <el-form-item label="身份证号:">
          <el-input v-model="form.idCard" ></el-input>
        </el-form-item>
        <el-form-item label="楼号" prop="buildingNumber">
            <el-input v-model="form.buildingNumber" ></el-input>
          </el-form-item>
          <el-form-item label="单元号" prop="unitNumber">
            <el-input v-model="form.unitNumber" ></el-input>
          </el-form-item>
          <el-form-item label="户号" prop="houseNumber">
            <el-input v-model="form.houseNumber" ></el-input>
          </el-form-item>
        <el-form-item label="出生年月日:">
         <el-date-picker
          v-model="form.birthday"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
        </el-form-item>
      </el-form>
      <el-button type="primary" style="margin-left:390px" @click="resetPserson">保存</el-button>
  </div>
</template>

<script>
import webservice from "../../utils/webservice";
export default {
  data(){
    return{
      form:{},
      isLimit:true
    }
  },
  created(){
    this.form = JSON.parse(window.sessionStorage.getItem('userInfo'))
    if(this.form){
      if(this.form.type==='1'){
         this.isLimit = false
      }else{
        this.isLimit = true
      }
    }
  },
  mounted(){

  },
  methods:{
    resetPserson(){
      let params = {
        id:this.form.id,
        name:this.form.name,
        type:this.form.type,
        gender:this.form.gender,
        phone:this.form.phone,
        idCard:this.form.idCard,
        birthday:this.form.birthday,
        buildingNumber:this.form.buildingNumber,
        unitNumber:this.form.unitNumber,
        houseNumber:this.form.houseNumber,
        
      }
      webservice.HttpPost(
        "/api/user/updateUserInfo",
        params,
        (data) => {
        if (data.code === 200) {
            this.$message.success({
                message: '修改成功！',
                showClose: true,
                duration: 1000,
            });
            this.$router.push('/index')
            let _param ={
              userId:this.form.id
            }
            webservice.HttpGet(
                "/api/user/getUserInfo",
                _param,
                (data) => {
                if (data.code === 200) {
                  window.sessionStorage.setItem('userInfo', JSON.stringify(data.data))
                  this.resetSetItem('userInfo',JSON.stringify(data.data));
                } else{
                      this.$message.error({
                          message: data.message,
                          showClose: true,
                          duration: 1000,
                      });
                    }
                }
            );
        } else{
              this.$message.error({
                  message: data.message,
                  showClose: true,
                  duration: 1000,
              });
            }
        }
    );
    }
  }
}
</script>

<style scoped>
.el-form{
  height: 400px;
  width: 500px;
  margin-top: 30px;
}
.el-input{
  width:60%;
}
.el-select{
  width:60%;
}
</style>